from playLA.Matrix import Matrix  ## 引入矩阵类
from playLA.Vector import Vecotr

if __name__ == "__main__":

    matrix = Matrix([[1,2] , [3,4]])  ## 简单的二维数组
    print(matrix)
    print("matrix.shape = {}".format(matrix.shape()))
    print("matrix.row_num = {}".format(matrix.row_num()))
    print("matrix.col_num = {}".format(matrix.col_num()))
    print("matrix.size = {}".format(matrix.size()))
    print("len(matrix) = {}".format(len(matrix)))
    print("matrix[0][0] = {}".format(matrix[0,0]))

    matrix2 = Matrix([[5,6] , [7,8]])
    print("add:{}".format(matrix+matrix2))
    print("subtract:{}".format(matrix-matrix2))
    print("scalar-mul:{}".format(matrix * 2))
    print("scalar-mul:{}".format(2 * matrix))
    print("truediv:{}".format(matrix / 2))
    print("pos:{}".format(+matrix))
    print("neg:{}".format(-matrix))
    print("zero_2_3:{}".format(Matrix.zero(2,3)))

    T = Matrix([[1.5 , 0] , [0,2]])
    p = Vecotr([5,3])
    print("T.dot(p) = {}".format(T.dot(p)))

    P = Matrix([[0,4,5] , [0,0,3]])
    print("T.dot(P) = {}".format(T.dot(P)))

    ## 矩阵乘法交换律 ？ A*B  B*A  （方阵） 结果不同~=！ 不遵循交换律！
    print("A.dot(B) = {}".format(matrix.dot(matrix2)))
    print("B.dot(A) = {}".format(matrix2.dot(matrix)))



    # 创建一个2×3矩阵
    m = Matrix([[1, 2, 3], [4, 5, 6]])
    print(m)  # Matrix([[1, 2, 3], [4, 5, 6]])
    print(m.T())  # Matrix([[1, 4], [2, 5], [3, 6]])

    # 验证转置性质
    print(m.shape())  # (2, 3)
    print(m.T().shape())  # (3, 2) 行数列数互换


    ## 单位矩阵
    I = Matrix.identity(2)
    print(I)

    print("A.dot(I) = {}".format(matrix.dot(I)))
    print("I.dot(A) = {}".format(I.dot(matrix)))



